package com.az.miaoauth.listener;

import com.az.miaoapi.exception.BaseException;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class LogoutListener {

    private final RedisTemplate<String, Object> redisTemplate;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "logout_queue", durable = "true"),
            exchange = @Exchange(value = "logout.direct"),
            key = {"logout_key"}))
    @Retryable(noRetryFor = BaseException.class)
    public void logout(Long userId) {
        redisTemplate.delete("login_users:" + userId);
        System.out.println("我听到了！！！");
    }
}
